import { Component, OnInit, EventEmitter } from '@angular/core';
import { UploadInput, UploadOutput } from 'ngx-uploader';
import { avatarSrc } from 'src/environments/environment';

@Component({
  selector: 'app-money',
  templateUrl: './money.component.html',
  styleUrls: ['./money.component.less']
})
export class MoneyComponent implements OnInit {

  avatar = '';

  // 上传配置
  uploadInput: EventEmitter<UploadInput> = new EventEmitter<UploadInput>();
  constructor() { }

  ngOnInit() {
  }

  onUploadOutput(output: UploadOutput) {

    console.log(output);
    if (output.type === 'allAddedToQueue') {
      this.uploadInput.emit({
        type: 'uploadAll',
        url: '/api/upload',
        method: 'POST',

      });
    } else if (output.type === 'done') {

      // 上传完成
      if (output.file.responseStatus === 200 && output.file.response.success) {
        this.avatar = avatarSrc + output.file.response.data;
      } else {
        alert('上传失败')
      }
    }
  }

}
